<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>设备管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" th:href="@{/favicon.ico}">
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet">
    <link th:href="@{/css/animate.css}" rel="stylesheet">
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <link th:href="@{/self/self-common.css}" rel="stylesheet">

    <link th:href="@{/css/plugins/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet">
    <link th:href="@{/css/plugins/bootstrap-select/bootstrap-select.css}" rel="stylesheet">

    <!--zTree-->
    <link th:href="@{/self/zTree/metroStyle.css}" rel="stylesheet"/>
    <!-- Sweet Alert -->
    <link th:href="@{/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">
</head>

<body class="gray-bg" id="layDate">

<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">设备类别</div>
            <div class="box-operation">
                <a id="clickAdd" title="新增"><i class="fa fa-plus"></i></a>
                <a id="clickUpdate" title="编辑"><i class="fa fa-edit"></i></a>
                <a id="clickDelete" title="删除"><i class="fa fa-trash"></i></a>
            </div>
        </div>

        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-resizer ui-layout-resizer-open">
    <div class="ui-layout-toggler" title="折叠">
        <span class="ui-content content-open" style="display: block;"><i class="fa fa-caret-left"></i></span>
        <span class="ui-content content-closed" style="display: none;"><i class="fa fa-caret-right"></i></span>
    </div>
</div>

<div class="ui-layout-center">
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row">


            <div class="col-sm-12 search-card">
                <div class="ibox">
                    <div class="ibox-content">

                        <form class="form-inline">
                            <div class="form-group searchCX">
                                <input id="search_device_sn" class="form-control" type="text" placeholder="请输入设备编号"
                                       clearable>
                            </div>
                            <div class="form-group searchCX">
                                <input id="search_device_name" class="form-control" type="text" placeholder="请输入设备名称"
                                       clearable>
                            </div>

                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-purple" type="button">
                                    <i class="fa fa-search"></i>
                                    查询
                                </button>
                            </div>
                        </form>

                    </div>
                </div>
            </div>

            <div class="col-sm-12 table-card">
                <div class="ibox">
                    <div class="ibox-title">
                        <h5>
                            <i class="fa fa-bookmark"></i>
                            设备管理
                        </h5>
                    </div>
                    <div class="ibox-content">
                        <div id="toolbar">
                            <form class="form-inline btnOpacity">
                                <div class="btn-group">
                                    <button class="btn btn-purple" type="button" id="btnAdd">
                                        <i class="fa fa-plus-circle"></i>
                                        新增
                                    </button>
                                </div>
                                <div class="form-group">
                                    <button id="importBtn" class="btn btn-purple" type="button" data-toggle="modal"
                                            data-target="#myModal">
                                        <i class="fa fa-upload"></i>
                                        导入
                                    </button>
                                </div>
                                <div class="form-group">
                                    <button id="export" class="btn btn-orange" type="button">
                                        <i class="fa fa-download"></i>
                                        导出
                                    </button>
                                </div>
                                <!--                                <div class="btn-group">-->
                                <!--                                    <button class="btn btn-orange" type="button" id="btnUpd">-->
                                <!--                                        <i class="fa fa-pencil-square-o"></i>-->
                                <!--                                        修改-->
                                <!--                                    </button>-->
                                <!--                                </div>-->
                                <!--                                <div class="btn-group">-->
                                <!--                                    <button class="btn btn-red" type="button" id="btnDelete">-->
                                <!--                                        <i class="fa fa-times"></i>-->
                                <!--                                        删除-->
                                <!--                                    </button>-->
                                <!--                                </div>-->
                            </form>
                        </div>
                        <table id="dataTable" data-mobile-responsive="true"></table>
                    </div>
                </div>
            </div>

            <div class="footer" style="">
                <div class="pull-right">&copy; 2019-2020 <a href="http://www.ruikongiot.com/"
                                                            target="_blank">无锡睿控物联网科技有限公司</a>
                </div>
            </div>
        </div>
        <!------------------------------------------设备------------------------------------------->
        <div class="modal inmodal fade" id="Modal">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title"></h4>
                        <button type="button" class="close" data-dismiss="modal">×</button>
                    </div>
                    <div class="modal-body">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">*设备编号：</label>
                                <div class="col-sm-7">
                                    <input id="device_sn" type="text" name="" class="form-control"
                                           placeholder="请输入设备编号">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">*设备名称：</label>
                                <div class="col-sm-7">
                                    <input id="device_name" type="text" name="" class="form-control"
                                           placeholder="请输入设备名称">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">*规格型号：</label>
                                <div class="col-sm-7">
                                    <input id="model" type="text" name="" class="form-control"
                                           placeholder="请输入规格型号">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">供应商：</label>
                                <div class="col-sm-7">
                                    <input id="supplier" type="text" name="" class="form-control"
                                           placeholder="请输入供应商">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">保养周期（天）：</label>
                                <div class="col-sm-7">
                                    <input id="maintenance_cycle" type="text" name="" class="form-control"
                                           placeholder="请输入保养周期（天）">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">购买日期：</label>
                                <div class="col-sm-8 tc-date2">
                                    <input id="buy_date" class="laydate-icon form-control layer-date outDate"
                                           placeholder="YYYY-MM-DD">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">安装日期：</label>
                                <div class="col-sm-8 tc-date2">
                                    <input id="install_date" class="laydate-icon form-control layer-date outDate"
                                           placeholder="YYYY-MM-DD">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">投产日期：</label>
                                <div class="col-sm-8 tc-date2">
                                    <input id="commissioning_date" class="laydate-icon form-control layer-date outDate"
                                           placeholder="YYYY-MM-DD">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">*设备状态：</label>
                                <div class="col-sm-8">
                                    <select id="state" class="selectpicker show-tick" data-live-search="true"
                                            title="设备状态">
                                        <option value="1">启用</option>
                                        <option value="0">停用</option>
                                    </select>
                                </div>
                            </div>
<!--                            <div class="form-group col-md-6">-->
<!--                                <label class="col-sm-3 control-label">设备运行状态：</label>-->
<!--                                <div class="col-sm-8">-->
<!--                                    <select id="is_used" class="selectpicker show-tick" data-live-search="true"-->
<!--                                            title="设备状态">-->
<!--                                        <option value="1">运行中</option>-->
<!--                                        <option value="0">未运行</option>-->
<!--                                    </select>-->
<!--                                </div>-->
<!--                            </div>-->
                            <div class="form-group col-md-12">
                                <label class="col-sm-3 control-label">备注：</label>
                                <div class="col-sm-7">
                                    <textarea id="remarks" placeholder="请输入备注" name="comment" class="form-control"
                                              required="" aria-required="true"></textarea>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white btn-close" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-purple btn-save" id="btnSave">保存</button>
                    </div>
                </div>
            </div>
        </div>

        <!------------------------------------------设备类型------------------------------------------->
        <div class="modal inmodal fade" id="typeModal">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title"></h4>
                        <button type="button" class="close" data-dismiss="modal">×</button>
                    </div>
                    <div class="modal-body">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">设备类别名称：</label>
                                <div class="col-sm-7">
                                    <input id="typename" type="text" name="" class="form-control"
                                           placeholder="请输入设备类别名称">
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white btn-close" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-purple btn-save" id="btnTypeSave">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <!--导入模态框-->
        <div class="modal inmodal fade" id="myModal">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">工单导入</h4>
                        <button type="button" class="close" data-dismiss="modal" onclick="removeImp()">×</button>
                    </div>
                    <div class="modal-body">
                        <div class="col-md-12">
                            <div class="form-group">
                                <div class="import_btn" style="width:100%;text-align:left">
                                    <label for="import"><span>选择文件</span></label>
                                    <span id="fileName">未上传文件</span>
                                </div>
                                <input type="file" id="import" onchange="loadFile(this.files[0])" name="import"
                                       style="width: 220px;opacity:0">
                            </div>
                            <div class="form-group">
                                <a class="downtele" style="text-align:left;" href="#" onclick="downLoadTemp();"><span
                                        style="padding:5px ;font-size:16px;font-weight:200;color:#337ab7">模板下载</span></a>
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white btn-close" data-dismiss="modal"
                                onclick="removeImp()">取消
                        </button>
                        <button type="button" class="btn btn-purple btn-save" id="btnSaveExl" onclick="mySubmit()">保存
                        </button>
                    </div>
                </div>
            </div>
        </div>


    </div>
</div>
<!-- 全局js -->
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<script th:src="@{/js/content.js}"></script>
<script th:src="@{/js/app.js}" type="text/javascript"></script>

<!-- Bootstrap table -->
<script th:src="@{/js/plugins/bootstrap-table/bootstrap-table.min.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<!--提示框-->
<script th:src="@{/js/plugins/layer/layer.min.js}"></script>
<!--下拉选择框-->
<script th:src="@{/js/plugins/bootstrap-select/bootstrap-select.js}"></script>
<!--日期-->
<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>

<!--bootstrap导出-->
<script th:src="@{/js/plugins/bootstrap-table-export/bootstrap-table-export.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table-export/tableExport.js}"></script>

<!--zTree-->
<script th:src="@{/self/zTree/jquery.ztree.all.min.js}"></script>
<script th:src="@{/self/zTree/self-zTree.js}"></script>
<script th:src="@{/js/plugins/sweetalert/sweetalert.min.js}"></script>


<script>

    var deviceTypeId = '';
    var deviceId = '';

    var addOrupd = 0;// 0--add   1--upd
    var deviceAddOrUpd = 0;

    var settingss = {
        view: {
            showIcon: false,
            showLine: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: -1
            },
            key: {
                name: "name"
            }
        },
        check: {
            enable: false,
            nocheckInherit: true
        },
        callback: {
            onClick: zTreeOnClick,
        }
    };

    function zTreeOnClick(event, treeId, treeNode) {
        deviceTypeId = treeNode.id;

        if (treeNode.pId == -1) {
            $("#clickAdd").attr('disabled', false);
            $("#clickUpdate").attr('disabled', true);
            $("#clickDelete").attr('disabled', true);
        } else {
            $("#clickAdd").attr('disabled', false);
            $("#clickUpdate").attr('disabled', false);
            $("#clickDelete").attr('disabled', false);
        }

        $('#dataTable').bootstrapTable('refresh');
        deviceId = '';
        ztreeStyle(event, treeId, treeNode)//改变ztree样式
    }

    $(document).ready(function () {

        function queryParams(params) {
            return {
                pageSize: params.pageSize,
                pageNumber: params.pageNumber,

                deviceSn: $.trim($("#search_device_sn").val()),
                deviceName: $.trim($("#search_device_name").val()),
                deviceTypeId: deviceTypeId,
            }
        }

        $('#dataTable')
            .bootstrapTable({
                url: baseUrl + "getDevicePageList",
                method: "post",
                queryParamsType: "",
                queryParams: queryParams,
                pageNumber: 1, //初始化加载第一页，默认第一页
                pageSize: 10, //每页的记录行数（*）
                striped: false, //是否显示行间隔色
                cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                search: false, //是否显示搜索框功能
                pagination: true, //是否分页
                showRefresh: false, //是否显示刷新功能
                showToggle: false,
                showColumns: false,
                // clickToSelect: true, //是否启用点击选中行
                // uniqueId: "indentId", //每一行的唯一标识，一般为主键列
                // idField: "indentId",
                formatSearch: function () {
                    return "设备管理";
                },
                iconSize: 'outline',
                sidePagination: "server", //服务端请求
                showExport: false,//显示导出按钮
                buttonsAlign: "right",  //按钮位置
                exportTypes: ['excel'],  //导出文件类型
                pageList: [10, 20, 30, 'all'],
                exportDataType: "basic",//导出类型 'basic':当前页, 'all', 'selected'.
                toolbar: '#toolbar', //工具按钮用哪个容器
                icons: {
                    refresh: 'glyphicon-repeat',
                    toggle: 'glyphicon-list-alt',
                    columns: 'glyphicon-list',
                    export: 'glyphicon-export'
                }
                , responseHandler: function (res) {
                    var rows = [];
                    if (res.total !== 0) {
                        rows = res.list;
                    }
                    var result = {
                        rows: rows,
                        total: res.total
                    };
                    return result;
                },
                onEditableSave: function (field, row, oldValue, $ele) {
                    //更新数据到数据库

                },
                columns: [{
                    field: 'deviceSn',
                    title: '设备编号',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'deviceName',
                    title: '设备名称',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'deviceTypeName',
                    title: '设备类型',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'model',
                    title: '规格型号',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'maintenanceCycle',
                    title: '保养周期(天)',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'supplier',
                    title: '供应商',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'buyDate',
                    title: '购买日期',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'installDate',
                    title: '安装日期',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'commissioningDate',
                    title: '投产日期',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'createTime',
                    title: '创建时间',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'personnelName',
                    title: '创建人',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'state',
                    title: '设备状态',
                    formatter: function (value, row, index) {
                        if (value == 0) {
                            return '停用';
                        } else if (value == 1) {
                            return "启用";
                        }
                    }
                },
                //     {
                //     field: 'isUsed',
                //     title: '设备运行状态',
                //     formatter: function (value, row, index) {
                //         if (value == 0) {
                //             return '未运行';
                //         } else if (value == 1) {
                //             return "运行中";
                //         }
                //     }
                // },
                    {
                    field: 'remarks',
                    title: '备注',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'operation',
                    title: '操作',
                    align: 'center',
                    width: '100',
                    formatter: function (value, row, index) {
                        var startBtn = "<button type='button' class = 'btn btngroup btn-xs czIcon icon_edit' onclick='editDevice(\"" + row.id + "\")' title='编辑'></button>";
                        var closeBtn = "<button type='button' class = 'btn btngroup btn-xs czIcon icon_close'  onclick='deleteDevice(\"" + row.id + "\")' title='删除'></button>";
                        return startBtn + closeBtn;
                    }
                }],

                onClickRow: function (row, $element) {
                    $('.info').removeClass('info');
                    $($element).addClass('info');
                    deviceId = row.id;
                }
            });

        $("#typeModal").on("hidden.bs.modal", function () {
            $("#typename").val("");
        });

        $("#Modal").on("hidden.bs.modal", function () {
            $("#device_sn").val("");
            $("#device_name").val("");
            $("#model").val("");
            $("#supplier").val("");
            $("#maintenance_cycle").val("");
            $("#buy_date").val("");
            $("#install_date").val("");
            $("#commissioning_date").val("");
            $("#state").val("");
            $("#state").selectpicker('refresh');
            $("#is_used").val("");
            $("#is_used").selectpicker('refresh');
            $("#remarks").val("");
        });

        $("#clickAdd").attr('disabled', true);
        $("#clickUpdate").attr('disabled', true);
        $("#clickDelete").attr('disabled', true);
    });

    var BuildTree = function () {
        PostWebApi("getDeviceTypeTree").done(function (data) {
            if (data.code == 0) {
                var info = data.data;
                if (info) {
                    zTreeObj = $.fn.zTree.init($("#tree"), settingss, info);
                    zTreeObj.expandAll(true);
                    deviceTypeId = '';
                }
            }
        })
    }
    BuildTree();

    //新增按钮
    $("#btnAdd").on('click', function (e) {
        if (deviceTypeId == "") {
            layer.msg("请先选择设备类别");
            return
        }
        deviceAddOrUpd = 0;
        $('#Modal .modal-header .modal-title').empty().text("新增设备");
        $('#Modal').modal();
    })

    //#region 设备修改
    //修改按钮
    function editDevice(editDeviceId) {
        PostWebApi("getDeviceById", {
            id: editDeviceId,
        }).done(function (data) {
            if (data.code == 0) {
                $("#device_sn").val(data.data.deviceSn);
                $("#device_name").val(data.data.deviceName);
                $("#model").val(data.data.model);
                $("#supplier").val(data.data.supplier);
                $("#maintenance_cycle").val(data.data.maintenanceCycle);
                $("#buy_date").val(data.data.buyDate);
                $("#install_date").val(data.data.installDate);
                $("#commissioning_date").val(data.data.commissioningDate);
                $("#state").val(data.data.state);
                $("#state").selectpicker('refresh');
                $("#is_used").val(data.data.isUsed);
                $("#is_used").selectpicker('refresh');
                $("#remarks").val(data.data.remarks);
                deviceAddOrUpd = 1;
                $('#Modal .modal-header .modal-title').empty().text("修改设备");
                $('#Modal').modal();
            }
        });
        deviceId = editDeviceId
    }

    //删除按钮
    function deleteDevice(deleteDeviceId) {
        swal({
            title: "您确定删除该设备吗",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "取消",
            confirmButtonColor: "rgb(85 221 218)",
            confirmButtonText: "确定",
            closeOnConfirm: false
        }, function () {
            swal.close();
            PostWebApi("deleteDevice", {
                id: deleteDeviceId
            }).done(function (data) {
                if (data.code === 0) {
                    layer.msg(data.msg);
                    $("#dataTable").bootstrapTable('refresh');
                    deviceId = '';
                } else {
                    layer.msg(data.msg);
                }
            });
        })
    }

    //搜索按钮
    $("#btnSearch").on('click', function (e) {
        $("#dataTable").bootstrapTable('refresh');
        deviceId = '';
    })
    //#endregion

    var reg = /^[0-9,.]*$/;

    //保存
    $("#btnSave").on('click', function (e) {
        var id;
        if (deviceAddOrUpd == 0) {
            id = 0;
        } else {
            id = deviceId;
        }
        if ($("#device_sn").val() == '') {
            layer.msg("设备编号不能为空")
            return
        }
        if ($("#device_name").val() == '') {
            layer.msg("设备名称不能为空")
            return
        }
        if ($("#state").val() == '') {
            layer.msg("请选择设备状态")
            return
        }
        PostWebApi("editDevice", {
            deviceSn:$("#device_sn").val(),
            deviceName: $("#device_name").val(),
            deviceTypeId: deviceTypeId,
            model: $("#model").val(),
            maintenanceCycle: $("#maintenance_cycle").val(),
            supplier: $("#supplier").val(),
            buyDate:$("#buy_date").val(),
            installDate: $("#install_date").val(),
            commissioningDate: $("#commissioning_date").val(),
            state:$("#state").val(),
            isUsed:$("#is_used").val(),
            remarks:$("#remarks").val(),
            id: id
        }).done(function (data) {
            if (data.code === 0) {
                layer.msg(data.msg);
                $("#Modal").modal('hide');
                $('#dataTable').bootstrapTable('refresh');
                deviceId = '';

            } else {
                layer.msg(data.msg);
            }
        });
    })

    //设备类别新增
    $("#clickAdd").on('click', function (e) {
        $('#typeModal .modal-header .modal-title').empty().text("新增设备类别");
        $('#typeModal').modal();
        addOrupd = 0;
        // BuildTree();
        // $('#dataTable').bootstrapTable('refresh');
    })

    //设备类别修改
    $("#clickUpdate").on('click', function (e) {
        PostWebApi("getDeviceTypeById", {
            deviceTypeId: deviceTypeId
        }).done(function (data) {
            if (data.code === 0) {
                $("#typename").val(data.data.deviceTypeName);
                $('#typeModal .modal-header .modal-title').empty().text("修改设备类别");
                $('#typeModal').modal();
                addOrupd = 1;
                //   BuildTree();
                // $('#dataTable').bootstrapTable('refresh');
            } else {
                layer.msg(data.msg);
            }
        });
    })

    //设备类别删除
    $("#clickDelete").on('click', function (e) {
        if (deviceTypeId == "") {
            layer.msg("请选择设备类别进行删除");
            return;
        }
        swal({
            title: "您确定删除该设备类别吗",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "取消",
            confirmButtonColor: "rgb(85 221 218)",
            confirmButtonText: "确定",
            closeOnConfirm: false
        }, function () {
            swal.close();
            PostWebApi("deleteDeviceType", {
                deviceTypeId: deviceTypeId
            }).done(function (data) {
                if (data.code === 0) {
                    layer.msg(data.msg);
                    BuildTree();
                    // 车间类型清空
                    deviceTypeId = 0;
                    // 刷新table
                    // $('#dataTable').bootstrapTable('refresh');
                } else {
                    layer.msg(data.msg);
                }
            });
        })
    })

    //保存
    $("#btnTypeSave").on('click', function (e) {
        var device_type_id;
        var device_type_pid;
        if (addOrupd == 0) {
            //新增
            //   device_type_pid = 0;
            device_type_pid = 0;
        } else {
            //修改
            device_type_id = deviceTypeId;
        }
        PostWebApi("editDeviceType", {
            deviceTypeName: $("#typename").val(),
            deviceTypePid: device_type_pid,
            deviceTypeId: device_type_id
        }).done(function (data) {
            if (data.code === 0) {
                layer.msg(data.msg);
                $("#typeModal").modal('hide');
                BuildTree();
                $('#dataTable').bootstrapTable('refresh');
            } else {
                layer.msg(data.msg);
            }
        });
    })

    //----------------------------EXCEL-------------------------------------
    // 使用tableExport.js导出数据
    $("#export").click(function () {
        $('#dataTable').tableExport(
            {
                type: 'excel',//导出excel
                escape: 'false',
                ignoreColumn: [10],  //忽略某一列的索引
                fileName: '设备信息',  //文件名称设置
                worksheetName: '设备信息',  //表格工作区名称
                tableName: '设备信息',
                excelstyles: ['background-color', 'color', 'font-size', 'font-weight']
            }
        )
    })

    //下载导入模版
    function downLoadTemp() {
        window.location.href = baseUrl + "downDeviceExcelTemplate?fileName=设备导入模版";
    }

    //移除文件文字
    function removeImp() {
        var file = document.getElementById('import');
        file.value = ''; //虽然file的value不能设为有字符的值，但是可以设置为空值
        //或者
        //file.outerHTML = file.outerHTML; //重新初始化了file的html
        $("#fileName").html('未上传文件');
    }

    //加载文件名
    function loadFile(file) {
        $("#fileName").html(file.name);
    }

    //导入excel文件信息
    function mySubmit() {
        var file = document.getElementById("import").files[0];
        var fileName = $("#fileName").val();
        var preffix = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.lastIndexOf("."));
        var suffix = fileName.substring(fileName.lastIndexOf("."));
        //创建新的表单数据对象
        var formData = new FormData();
        formData.append("file", file);
        formData.append("preffix", preffix);
        formData.append("suffix", suffix);
        $.ajax({
            url: baseUrl + "deviceImport",
            type: "POST",
            contentType: false,
            datatype: "text",
            data: formData,
            processData: false, // 告诉jQuery不要去处理发送的数据
            success: function (data) {
                $('#dataTable').bootstrapTable('refresh');
                layer.msg(data.msg)
            }
        });
        removeImp();
        $('#myModal').modal('hide');
        return false;
    }

    laydate({
        elem: '#layDate .outDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
        event: 'focus' //响应事件。如果没有传入event，则按照默认的click
    });

</script>

</body>

</html>

